<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>提交</title>
</head>
<body>
<input type="file" id="file">
<button onclick="getCode()">ttttt</button>
<button onclick="getCode2()">ttttt</button>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>





    // $(document).ready(function(){
    //     let file = document.querySelector('#file');
    //
    //     // getCode(file)
    // })
    function getCode2() {
        $.ajax({
            url:"http://127.0.0.1:9999/onlineApp/paper/details/test/1",
            method:"post",
            contentType: "application/json",
            data:JSON.stringify([1,2,3]),
            success:function(result){
                if(result.code == 200){
                    if(type == 0)
                        $('#code0').val(result.data)
                    else
                        $('#code1').val(result.data)
                }
                else
                    alert(result.message)
            }
        });
    }


    function getCode() {
        let file = document.querySelector('#file');
        let formData = new FormData();
        let data = {
            "subjectsDetails" : [
                {
                    "subjectId": 2,
                    "userAnswer": "asd",
                    "hasFile": 1
                },
                {
                    "subjectId": 2,
                    "userAnswer": "123"
                }
            ]
        }
        // "subjectId":3,
        formData.append("file",file.files[0]);
        formData.append("file",file.files[0]);
        formData.append("file",file.files[0]);
        let index = [1,2,3]
        formData.append("index",new Blob([JSON.stringify(index)], {type: "application/json"}));

        //
        formData.append("data",new Blob([JSON.stringify(data)], {type: "application/json"}));
        // formData.append("data",d);
        $.ajax({
            url:"http://127.0.0.1:9999/onlineApp/paper/details/1",
            method:"post",
            cache: false, contentType: false, processData: false,
            data:formData,
            success:function(result){
                if(result.code == 200){
                    if(type == 0)
                        $('#code0').val(result.data)
                    else
                        $('#code1').val(result.data)
                }
                else
                    alert(result.message)
            }
        });
    }


</script>
</body>
</html>